﻿using System;
using System.Collections.Generic;
using System.Text;

namespace OkTool.Util
{
    public class ByteUtil
    {
        /// <summary>
        /// int转byte
        /// </summary>
        /// <param name="intValue"></param>
        /// <returns></returns>
        public static byte IntToByte(int intValue)
        {
            return (byte)intValue;
        }


        public static long BytesToLong(byte[] bytes, int start, bool isLittleEndian)
        {
            long values = 0;

            if (isLittleEndian)
            {
                for (int i = (sizeof(long) - 1); i >= 0; i--)
                {
                    values <<= 8;
                    values |= (bytes[i + start] & 0xff);
                }
            }
            else
            {
                for (int i = 0; i < sizeof(long); i++)
                {
                    values <<= 8;
                    values |= (bytes[i + start] & 0xff);
                }
            }

            return values;
        }
    }
}
